import { getSystemConfig } from '@/api/system';
import { LOCAL_KEY } from '@/constant/dict';

const state = {
    // 是否已经初始化,不需要再Wizard，true：进入wizard，false 正常往下走
    isWizard: false,

    is24gEnable: false,
    is5GEnable: false,
    is6GEnable: false,

    isLoadConfig: false,

    // 漫游状态
    isRoamStatus: false, 
    /**
     * sim 状态 connected disconnected
     */ 
    simStatus: "connected"
};

const config = {
    namespaced: true,
    state,
    actions: {
        async LOAD_CONFIG({ commit }) {
            if(!state.isLoadConfig){
                try {
                    console.log('getSystemConfig');
                    const { isWizard,is2_4g_enable,is5g_enable,is6g_enable,main_status} = await getSystemConfig();
                    state.isLoadConfig = true;
                    console.log('config getSystemConfig success');
                    commit('SET_WIZARD', isWizard);
                    commit('SET_24G_ENABLE', is2_4g_enable);
                    commit('SET_5G_ENABLE', is5g_enable);
                    commit('SET_6G_ENABLE', is6g_enable);
                    commit('SET_SIM_STATUS', main_status);
                } catch (error) {
                    console.error('获取配置信息出错:', error);
                }
            }

            return state.isWizard;
        },
        UPDATEROAM({ commit }, value) {
            commit('SET_ROAM_STATUS', value);
            return this.isRoamStatus;
        },
    },
    mutations: {
        SET_WIZARD: (state, value) => {
            state.isWizard = value;
        },
        SET_LOAD_CONFIG: (state, value) => {
            state.isLoadConfig = value;
        },
        SET_24G_ENABLE: (state, value) => {
            state.is24gEnable = value;
        },
        SET_5G_ENABLE: (state, value) => {
            state.is5GEnable = value;
        },
        SET_6G_ENABLE: (state, value) => {
            state.is6GEnable = value;
        },
        SET_ROAM_STATUS: (state, value) => {
            state.isRoamStatus = value;
        },
        SET_SIM_STATUS: (state, value) => {
            state.simStatus = value;
        },
    }
};

export default config;
